﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class Controls_Tour_ctrTourPopularList : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLang = Support.GetDefaultLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataToTourPopular();
            BindTourPromotion();
        }
    }

    private void BindDataToTourPopular()
    {
        TourPopular objTourPopular = new TourPopular();
        DataTable dtbTourPopular = objTourPopular.Search_IsHome();

       
        rptTourPopular.DataSource = dtbTourPopular;
        rptTourPopular.DataBind();
        rptGroup.DataSource = dtbTourPopular;
        rptGroup.DataBind();

        lblPerfectJustClick.Text = MultipleLanguage.PERFECTJUSTCLICK[nCurrentLang - 1];
      
    }

    private void BindTourPromotion()
    {
        int nPageCount = 0;
        SaleOff objSale = new SaleOff();
        DataTable dtbSale = new DataTable();
        dtbSale = objSale.GetALL();
        int nCount = dtbSale.Rows.Count;
        if (nCount > 0)
        {
            switch (nCurrentLang)
            {
                case 1:
                    lblPromotion.Text = ConvertData.ConvertToString(dtbSale.Rows[nCount - 1]["Title1"]);
                    break;
                case 2:
                    lblPromotion.Text = ConvertData.ConvertToString(dtbSale.Rows[nCount - 1]["Title2"]);
                    break;
                case 3:
                    lblPromotion.Text = ConvertData.ConvertToString(dtbSale.Rows[nCount - 1]["Title3"]);
                    break;
            }

            int nPromotionID = ConvertData.ConvertToInt(dtbSale.Rows[nCount - 1]["SaleOffID"]);

            Tours objTour = new Tours();
            DataTable dtbTour = new DataTable();
            dtbTour = objTour.Search(4, 0, "", 0, 0, 0, nPromotionID, 0, 0, "", nDefaultLang, nCurrentLang, -1, 1, 1, 4, ref nPageCount);
            rptPromotion.DataSource = dtbTour;
            rptPromotion.DataBind();
            lnkShowall.NavigateUrl = "~/TourCategory.aspx?" + Config.TOUR_SALEOFF + "=" + nPromotionID + "&cid=" + GetCountry();
        }
        lnkShowall.Text = MultipleLanguage.GETMORETOUR[nCurrentLang - 1];

    }

    private int GetCountry()
    {
        int nReturn = ConvertData.ConvertToInt(Request.QueryString["cid"]);
        if (nReturn ==0)
            nReturn = 1;
        return nReturn;
    }

    protected void rptTourPopular_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Label ltrTab = (Label)e.Item.FindControl("ltrTab");
            switch (nCurrentLang)
            {
                case 1:
                    ltrTab.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description1"));
                    break;
                case 2:
                    ltrTab.Text =  ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description2"));
                    break;
                case 3:
                    ltrTab.Text =  ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Description3"));
                    break;
            }
        }
    }
    protected void rptTourPopularContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            int nCurrentLanguage = Support.GetCurrentLanguage();
            int nDefaultLanguage = Support.GetDefaultLanguage();

            HyperLink lnkTourName = (HyperLink)e.Item.FindControl("lnkTourName");
            HyperLink lnkReadMore = (HyperLink)e.Item.FindControl("lnkReadMore");
            lnkReadMore.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID")) + "&cid="+ this.GetCountry();
            lnkReadMore.Text = MultipleLanguage.LNK_READMORE[nCurrentLanguage - 1];
            Label lblDuration = (Label)e.Item.FindControl("lblDuration");

            lnkTourName.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID")) + "&cid=" + this.GetCountry();

            ImageButton imgTour = (ImageButton)e.Item.FindControl("imgTour");
            imgTour.ImageUrl = Config.ROOT + Config.IMAGE_TOUR_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            imgTour.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));

            Literal ltrTour = (Literal)e.Item.FindControl("ltrTour");
            string sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            if (sInitContent.Length > 115)
                sInitContent = ConvertData.TruncateString(sInitContent, 115) + "...";
            ltrTour.Text = sInitContent;
            lnkTourName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title"));

            switch (nCurrentLang)
            { 
                case 1:
                    lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription1"));
                    break;
                case 2:
                    lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription2"));
                    break;
                case 3:
                    lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription3"));
                    break;
            }
        }
    }
    protected void rptTour_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + nID + "&cid="+ this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }

    protected void rptTourPopularContent_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + nID + "&cid="+ this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }

    protected void rptGroup_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        int nPageCount = 0;
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            Repeater rptTourPopularContent = (Repeater)e.Item.FindControl("rptTourPopularContent");
            HyperLink lnkPerfectMore = (HyperLink)e.Item.FindControl("lnkPerfectMore");
            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "TourPopularID"));


            Tours objTour = new Tours();
            DataTable dtbTour = new DataTable();
            dtbTour = objTour.Search(3, 0, "", 0, 0, nID, 0, 0, 0, "", nDefaultLang, nCurrentLang, -1, 1, 1, 3, ref nPageCount);
            rptTourPopularContent.DataSource = dtbTour;
            rptTourPopularContent.DataBind();

            lnkPerfectMore.Text = MultipleLanguage.GETMORETOUR[nCurrentLang - 1];
            lnkPerfectMore.NavigateUrl = "~/TourCategory.aspx?" + Config.TOUR_POPULAR + "=" + nID + "&cid=" + GetCountry();
        }


       
     
    }
    protected void rptPromotion_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            int nCurrentLanguage = Support.GetCurrentLanguage();
            int nDefaultLanguage = Support.GetDefaultLanguage();

            HyperLink lnkTitle = (HyperLink)e.Item.FindControl("lnkTitle");
            HyperLink lnkRedmore = (HyperLink)e.Item.FindControl("lnkRedmore");
            Label lblDuration = (Label)e.Item.FindControl("lblDuration");

            lnkTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID")) + "&cid=" + this.GetCountry();

            ImageButton imgImage = (ImageButton)e.Item.FindControl("imgImage");
            imgImage.ImageUrl = Config.ROOT + Config.IMAGE_TOUR_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            imgImage.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));

            Label lblInitContent = (Label)e.Item.FindControl("lblInitContent");
            string sInitContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
            if (sInitContent.Length > 190)
                sInitContent = ConvertData.TruncateString(sInitContent, 190) + "...";
            lblInitContent.Text = sInitContent;
            lnkTitle.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title"));

            lnkRedmore.Text = MultipleLanguage.LNK_READMORE[nCurrentLang - 1];
            lnkRedmore.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID")) + "&cid=" + this.GetCountry();

            switch (nCurrentLang)
            {
                case 1:
                    lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription1"));
                    break;
                case 2:
                    lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription2"));
                    break;
                case 3:
                    lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription3"));
                    break;
            }
        }
    }
    protected void rptPromotion_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + nID + "&cid="+ this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }
}